home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 11978 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.7 KB  |  56 lines

  1. Path: news1.erols.com!newsmaster@erols.com
  2. From: Chris Cobb <ccobb@erols.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: SEX & C++
  5. Date: 17 Mar 1996 14:27:37 GMT
  6. Organization: CSEG, Inc.
  7. Message-ID: <4ih7gp$tdt@news5.erols.com>
  8. References: <4idbcv$ue2@news7.erols.com>
  9. NNTP-Posting-Host: ccobb.erols.com
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 1.22KIT (Windows; U; 16bit)
  14.  
  15. OK, so the subject line is only half true.  But now that I have your 
  16. attention, can someone please tell me if the following code works on 
  17. their compiler and/or if the code is conformant ANSI C++.  I have tried 
  18. it on three recent-version C++ compilers and it only works on one of 
  19. them.  Since this is such a simple example and will only take you a 
  20. couple of minuites to enter into your compiler, I challenge you all to 
  21. find out if this works on your compiler.
  22.  
  23. The implications are tremendous.  If I have a constant, MYCONST, that is 
  24. defined in a header xxx.h, and let's say twenty-five other source files 
  25. use it: if I change MYCONST, then I have to recompile twenty-five source 
  26. files.  
  27.  
  28. In the following scenario, I only have to recompile ONE source file, and 
  29. all of the rest can be used without recompiling.  Try it out!
  30.  
  31. --- xxx.h ---
  32. extern const int MYCONST; // can you declare a const extern?
  33. --- end xxx.h ---
  34.  
  35. --- xxx.cc ---
  36. #include "xxx.h"
  37. const int MYCONST = 11;   // const defined in one file...
  38. --- end xxx.cc ---
  39.  
  40. --- yyy.cc ---
  41. #include <iostream.h>
  42. #include "xxx.h"
  43. main()
  44. {
  45.    char myarray[MYCONST];  // and used in another!
  46.  
  47.    cout << "MYCONST is " << MYCONST << endl;
  48.    cout << "sizeof myarray[] is " << sizeof(myarray) << endl;
  49.    return 0;
  50. }
  51. --- end yyy.c ---
  52.  
  53. Chris
  54. ccobb@cseg.com
  55.  
  56.